home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3346 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: quick decision: is n a power of 2?
  5. Date: Sun, 28 Jan 96 01:12:22 GMT
  6. Organization: none
  7. Message-ID: <822791542snz@genesis.demon.co.uk>
  8. References: <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca> <TANMOY.96Jan21104404@qcd.lanl.gov> <4e6rs0$dvl@ns.RezoNet.NET> <9601251245.AA12220@dxmint.cern.ch>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <9601251245.AA12220@dxmint.cern.ch>
  15.            danpop@mail.cern.ch "Dan Pop" writes:
  16.  
  17. >The unary minus operator applied to an unsigned integer is always evaluated
  18. >using two's complement arithmetic, no matter what representation is used
  19. >by the implementation for signed integers.
  20.  
  21. Not exactly. Two's complement is a representation for signed integers so
  22. unsigned arithmetic clearly doesn't use it. However the nice thing about
  23. 2's complement arithmetic is that in most instances the underlying bit
  24. manipulations are (or can be for a suitable definition of overflow behaviour)
  25. the same as those for unsigned arithmetic (so at the archetecture
  26. level a single form of, e.g. an ADD instruction, can deal with both).
  27.  
  28. So the expression (-5) and (-5U) are each evaluated by its own set of rules
  29. but where signed integers are represented in 2's complement the 2 results
  30. will have the same underlying bit pattern.
  31.  
  32. >Tanmoy's point was that by restricting the solution to unsigned integers, 
  33. >the representation of signed integers becomes irrelevant.
  34.  
  35. That's my point too! :-)
  36.  
  37. -- 
  38. -----------------------------------------
  39. Lawrence Kirby | fred@genesis.demon.co.uk
  40. Wilts, England | 70734.126@compuserve.com
  41. -----------------------------------------
  42.